package it.allerj.common.persistence;

import it.allerj.common.i18n.StaticString;

import java.io.Serializable;



/**
 * @created 27-gen-2006 11.56.07
 * @author Alessandro Veracchi
 * @version 1.0
 */
public abstract class PersistenceObject implements Serializable, Comparable<Object> {
	public static int UNSAVED_VALUE = 0;
	private int id = UNSAVED_VALUE;
	

	public PersistenceObject(){
	}

	/**
	 * 
	 * @exception Throwable Throwable
	 */
	@Override
	public void finalize()
	  throws Throwable{

	}

  public void setId(int id) {
    this.id = id;
  }

  public int getId() {
    return id;
  }
  
  
  

	@Override
	public boolean equals(Object obj) {
		if (obj!=null && this.getClass().getName().split("\\$\\$")[0].equals(obj.getClass().getName().split("\\$\\$")[0]) && this.getId()==((PersistenceObject)obj).getId())
			return true;
		else return false;	
	}
  
	public String getLabelledValue(){
		return this.getClass().getName()+"#"+this.getId();
	}
	
	public String getLabelledName(){
		return StaticString.getString(this.getClass().getName());
	}

	public int compareTo(Object o) {
		if (o instanceof PersistenceObject) {
			PersistenceObject po = (PersistenceObject) o;
			return this.getLabelledValue().compareTo(po.getLabelledValue());
		}
		return -1;
	}
	
	
  
  
  
  
}
